package com.qf.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import javax.xml.ws.spi.WebServiceFeatureAnnotation;
import java.util.concurrent.TimeUnit;

/**
 * redis分布式锁工具类
 */
@Component
public class RedisLockUtil {
    @Autowired
    private StringRedisTemplate redisTemplate;
    //加锁
    public  boolean lock(String key,String value,int second){
        return redisTemplate.opsForValue().setIfAbsent(key,value,second, TimeUnit.SECONDS);
    }

    //解锁
    public void unLock(String key){
        redisTemplate.delete(key);
    }
}
